/**
 * Like product
 */

import expired from '@/config/expired'
import * as cache from '@/util/cache'
import md5 from 'js-md5'
const key = 'L' + md5('like')

export default {
  namespaced: true,
  state: {
    like: null
  },
  getters: {
    like: state => {
      if (state.like === null) {
        state.like = cache.get(key)
      }
      return state.like
    }
  },
  mutations: {
    SET_DATA: (state, data) => {
      state.like = data
      cache.save(key, data, expired.likeProductExpired)
    }
  },
  actions: {
    set_data: ({ commit }, data) => {
      commit('SET_DATA', data)
    }
  }
}
